<?php

namespace Cli\Controller;

use Cli\Controller\CommonController;
use Library\Wx;
use Library\WxPay;
use Think\Log;

/**
 * 微信卡券命令行接口, 
 */
class WxController extends CommonController {

    public function getAllPage() {
        print_r(Wx::searchShakeAroundPage('', 0, 10));
    }

    public function bindPage() {
        ini_set("auto_detect_line_endings", true);
        $file_name = "/root/test.csv";
        $file = fopen($file_name, "r");
        $log = fopen($file_name . '.log', "w");
        $error_log = fopen($file_name . '.error.log', "w");

        if (feof($file)) {
            echo 'feof';
        }

        fgetcsv($file, 0, ',');
        while (!feof($file)) {
            $line = fgetcsv($file, 0, ',');
            if (!$line) {
                echo 'fgetcsv error';
                break;
            }

            $page_ids = array(3088340);
            $result = Wx::bindPageShakeAroundDevice((int) $line[1], $page_ids);

            if (is_array($result)) {
                $line[] = $result['errcode'];
                fputcsv($log, $line);
            } else {
                fputcsv($error_log, $line);
            }
        }
        fclose($file);
        fclose($log);
        fclose($error_log);
    }

    public function SbindPage() {
        $page_ids = array(3088340);
        $result = Wx::bindPageShakeAroundDevice(5753560, $page_ids);

        var_dump($result);
    }

    public function get_order_status(){
        $info['mch_billno'] = $_SERVER['argv']['2'];
        $wxPay =  new \Library\WxPay();
        if ($wxPay->get_order_status($info)) {
            return 0;
        }
    }
}
